import { v4 as uuidv4 } from 'uuid';
import { Seeder } from '../../umzug';

const openedQuestionnaireUuid = uuidv4();
const closedQuestionnaireUuid = uuidv4();

export const openedQuestionnaire = {
  id: 1,
  uuid: openedQuestionnaireUuid,
  open: 1,
  name: 'openedQuestionnaire',
  fk_template: 1,
  job_position_visible: 0,
  affiliated_visible: 0,
  work_unit_visible: 0,
  operating_post_visible: 0,
  created_at: new Date(),
  updated_at: new Date()
};

export const closedQuestionnaire = {
  id: 2,
  uuid: closedQuestionnaireUuid,
  open: 0,
  name: 'closedQuestionnaire',
  fk_template: 1,
  job_position_visible: 1,
  affiliated_visible: 1,
  work_unit_visible: 1,
  operating_post_visible: 1,
  created_at: new Date(),
  updated_at: new Date()
};

const seedQuestionnaires = [
  openedQuestionnaire,
  closedQuestionnaire
];

export const up: Seeder = async ({ context: sequelize }) => {
  await sequelize
    .getQueryInterface()
    .bulkInsert('questionnaires', seedQuestionnaires);
};

export const down: Seeder = async ({ context: sequelize }) => {
  await sequelize.getQueryInterface().bulkDelete('questionnaires',
    { id: seedQuestionnaires.map((u) => u.id) });
};
